package com.fantasy.easy.biz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fantasy.easy.biz.domain.BizBase;
import com.fantasy.easy.biz.domain.BizColla;
import com.fantasy.easy.biz.domain.BizData;
import com.fantasy.easy.biz.service.BizBaseService;
import com.fantasy.easy.biz.service.BizCollaService;
import com.fantasy.easy.biz.service.BizDataService;
import com.fantasy.easy.core.SessionSubjectUtils;
import com.fantasy.easy.core.entity.SysUserEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author sdehua-帅德华
 * @Email sdhstart@qq.com
 * @Date 2022/6/24 14:47
 * @Version 1.0
 **/
@RestController
@RequestMapping("colla")
public class BizCollaController {

    @Resource
    BizCollaService bizCollaService;
    @Resource
    BizBaseService bizBaseService;

    @GetMapping("info")
    public IPage<BizColla> getInfo(@RequestBody(required = false) BizColla bizColla, Page<BizColla> p){
        SysUserEntity user = SessionSubjectUtils.getUserEntity();
        if (!user.getName().equals("admin")){
            int id = bizBaseService.getIdByName(user.getName());
            BizColla colla = new BizColla();
            colla.setId(id);
            return bizCollaService.queryAll(colla,p);
        }
        return bizCollaService.queryAll(bizColla,p);
    }

    @PostMapping("add")
    public int addInfo(@RequestBody BizColla bizColla){
        return bizCollaService.insert(bizColla);
    }


}
